package com.pomty.pombook;

import android.content.Context;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;

public class MediaScannerNotifier implements 
MediaScannerConnectionClient { 
    private Context mContext; 
    private MediaScannerConnection mConnection; 
    private String mPath; 
    private String mMimeType; 
    private Runnable mOnCompleteRunnable;

    public MediaScannerNotifier(Context context, String path, String 
mimeType) { 
        mContext = context; 
        mPath = path; 
        mMimeType = mimeType; 
        mConnection = new MediaScannerConnection(mContext, this); 
        mConnection.connect(); 
    } 
    

    public MediaScannerNotifier(Context context, String path, String 
mimeType, Runnable runnable) { 
        mContext = context; 
        mPath = path; 
        mMimeType = mimeType; 
        mOnCompleteRunnable = runnable;
        mConnection = new MediaScannerConnection(mContext, this); 
        mConnection.connect(); 
    } 
    public void onMediaScannerConnected() { 
        mConnection.scanFile(mPath, mMimeType); 
    } 
    public void onScanCompleted(String path, final Uri uri) { 
            mConnection.disconnect(); 
            mContext = null; 
            if (mOnCompleteRunnable != null)
            {
            	mOnCompleteRunnable.run();
            }
    } 
} 